<template>
  <!-- 添加账号页面 -->
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>添加账号</span>
    </div>
    <el-form :label-position="labelPosition" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="acc"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="pwd"></el-input>
      </el-form-item>
      <el-form-item label="用户组">
        <el-select v-model="userGrop" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-button type="primary" size="medium" @click="clickAdd">添加</el-button>
    <el-button size="medium">重置</el-button>
  </el-card>
</template>

<script>
import { userAdd } from "../../../../api/apis.js";
export default {
  data() {
    return {
      labelPosition: "left",
      acc: "", //密码
      pwd: "", //账号
      userGrop: "", //用户组：普通管理员/超级管理员
      options: [
        {
          value: "超级管理员",
          label: "超级管理员",
        },
        {
          value: "普通管理员",
          label: "普通管理员",
        },
      ],
    };
  },
  methods: {
    //   点击添加按钮函数
    clickAdd() {
      // 自动添加账号测试
      // for (let i = 0; i <= 100; i++)
      //   userAdd("acc" + i, "acc" + i, i % 2 == 0 ? "超级管理员" : "普通管理员");
      // 调用封装好的函数接口 使用axios
      userAdd(this.acc, this.pwd, this.userGrop).then((res) => {
        if (res.data.code == 0) {
          this.$message({
            message: "美团系统提示：添加账号成功",
            type: "success",
          });
        } else this.$message.error("美团系统提示：添加账号失败");
      });
    },
  },
};
</script>

<style lang="less" scoped>
.box-card {
  width: 100%;
  .text {
    font-size: 14px;
  }
  .el-form {
    width: 34%;
  }
}
</style>